package hn.cch.common.core;

import hn.cch.common.util.StreamUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Param {

    private static Logger logger = LoggerFactory.getLogger(Param.class);

    public static String listen_port = "listen.port";


    private static Properties properties;

    public static void initParam(File file){
        properties = new Properties();
        InputStream inputStream = StreamUtil.toInput(file);
        try {
            properties.load(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
            logger.error("properties load Exception Message: " + e.getMessage());
        }
    }

    public static String getString(String key){
        String value = properties.getProperty(key);
        return value;
    }

    public static Integer getInteger(String key){
        Integer value = Integer.parseInt(getString(key));
        return value;
    }

    public static void main(String[] args) {

        initParam(new File(Path.PARAM_PATH));

        int listenPort = getInteger(listen_port);

        logger.info("listenPort:" + listenPort);


    }
}
